<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="__PUBLIC__/js/jquery-easyui-1.5.1/themes/default/easyui.css">
    <link rel="stylesheet" href="__PUBLIC__/js/jquery-easyui-1.5.1/themes/icon.css">

    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/jquery.min.js"></script>
    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/plugins/jquery.layout.js"></script>

    <script src="__PUBLIC__/JS/myfun.js"></script>


    <title>请假管理</title>

</head>
<script>
    $(function () {
        $('#tt').datagrid({
            striped: true,
            idField: 'id',
            pagination: true,
            pageSize: 20,
            fitColumns: true,
            url: "{:U('home/leave/getlist','')}",
            width: '100%',
            rownumbers: true,
            singleSelect: true,
            iconCls: 'icon-save',
            toolbar: '#tb',


            columns: [[

                {field: 'id', title: '编码', hidden: true, width: 30},
                {field: 'name', title: '名称', width: 30},

                {
                    field: 'starttime', title: '开始时间', width: 80, align: 'right',
                    formatter: function (value) {
                        return new Date(value * 1000).toLocaleString();
                    }
                },
                {
                    field: 'stoptime', title: '结束时间', width: 80, align: 'right',
                    formatter: function (value) {
                        return new Date(value * 1000).toLocaleString();
                    }
                },
                {
                    field: 'duration', title: '时长', width: 30, align: 'right',
                    formatter: function (value, row, index) {
                        if (row.leixing == 1) {
                            return value / 2 + " 小时";
                        }
                        else {
                            var hours = value / 2;
                            if (hours >= 8) {
                                var days = Math.floor(hours / 8);
                                var hour = hours % 8;
                                return days + '天' + hour + "小时";
                            } else {
                                return value / 2 + " 小时";
                            }
                        }
                    }
                },
                {
                    field: 'leixing', title: '类型', width: 20, align: 'right',
                    formatter: function (value) {
                        if (value == 1) {
                            return '<span style="background-color:cornflowerblue;">加班</span>';

                        } else {
                            return '<span style="background-color:indianred;color: ivory">请假</span>';
                        }
                    }
                },
                {field: 'beizhu', title: '备注', width: 180},
                {
                    field: 'pend', title: '审核', width: 60, align: 'right',
                    formatter: function (value, row) {
                        var d = '----<a href="#" id="link_delete" onclick="deleterow(' + row.id + ')">删除</a>';
                        if (value == '1') {
                            return '<span style="color:blue">已审核</span>' + d;
                        }

                        return '<a href="#" style="color:red"  onclick="pendrow(' + row.id + ')">未审核</a>' + d;
                    }
                },

            ]]
        });


    });
    function addlevae() {
        $('#win').window({
            width: 600,
            height: 400,
            modal: true,
            href: "{:U('home/Leave/add')}",
        });
    }


    function pendrow(index) {



        $.messager.confirm('Confirm', '确认审核吗?', function (r) {
            if (r) {

                var posturl = "{:U('home/leave/pendrecord')}";
                $.post(posturl, {'id': index}, function (data) {
                    $.messager.alert('消息', data.info, 'info');
                    $('#tt').datagrid('reload');
                });


            }
        });
    }
    function deleterow(index) {

        $.messager.confirm('Confirm', '确认删除吗?', function (r) {
            if (r) {
                var posturl = "{:U('home/leave/deleterecord')}";
                $.post(posturl, {'id': index}, function (data) {
                    $.messager.alert('消息', data.info, 'info');
                    $('#tt').datagrid('reload');
                });
            }
        })

    }
    function doSearch() {
        $('#tt').datagrid('load', {
            starttime: $('#itemid').datebox('getText'),
            donetime: $('#productid').datebox('getText'),
            memid: $('#cc').combobox('getValues'),
            pendid: $('input:checked').val(),

        });
    }
</script>
<body>
<div>
    <a id="btn_ser" href="#" class="easyui-linkbutton" onclick="addlevae()" data-options="iconCls:'icon-add'">新建请假条</a>
    <br>
    <notempty name="Think.session.islogin">
        <table id="tt">

        </table>
        </notempty>

    <div id="win"></div>

</div>
<div id="tb" style="padding:3px">
    <form id="ff2" action="">
        <span>
         <span>开始时间</span>
    <input id="itemid" class="easyui-datebox" style="line-height:26px;border:1px solid #ccc">
    <span>结束时间</span>
    <input id="productid" class="easyui-datebox" style="line-height:26px;border:1px solid #ccc">
    </span>
        <span>
     成员选择
    <select id="cc" class="easyui-combobox" data-options="multiple:true" name="dept[]" style="width:200px;">
        <option selected="selected" value="0">--全部成员--</option>
        <foreach name="members" item="vo">
            <option value="{$vo.id}">{$vo.name}</option>
        </foreach>
    </select>
        </span>

        <br>

        <input type="radio" checked="checked" value="-1" name="filtermem">全部显示
        <input type="radio" value="1" name="filtermem">只显示请假
        <input type="radio" value="0" name="filtermem">只显示加班
        <span>|</span>
        <a href="#" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-search'" onclick="doSearch()">Search</a>

    </form>

</div>
</body>
</html>